<!DOCTYPE html>
<title>IndexedDB: Don't crash accessing cached properties in disconnected frame</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script id="scriptid" type="javascript/frame-script">
// This script is run in an IFRAME.

var dbname = 'db-' + String(document.location);
indexedDB.deleteDatabase(dbname);
var open = indexedDB.open(dbname);
open.onupgradeneeded = function() {
  var db = open.result;
  var store = db.createObjectStore('store');
};

open.onsuccess = function() {
  db = open.result;
  var tx = db.transaction('store');
  var req = tx.objectStore('store').get(0);
  req.onsuccess = function() {
    frameElement.parentNode.removeChild(frameElement);
    var result = req.result;
  };
};
</script>

<script>
async_test(function(t) {
    var script = document.querySelector('#scriptid').textContent;
    var blob = new Blob(['<script>', script, '<\/script>'], {'type': 'text/html'});
    var iframe = document.createElement('iframe');
    document.documentElement.appendChild(iframe);
    iframe.src = URL.createObjectURL(blob);

    // Wait for IFRAME to remove itself; the test passes as long as it
    // does not crash.
    var id = setInterval(t.step_func(function() {
        if (!document.querySelector('iframe')) {
            clearInterval(id);
            t.done();
        }
    }), 10);

}, 'Accessing cached attributes after frame disconnect should not crash.');
</script>
